
package org.example.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @Author author
 * @Create 2023-09-05 10:19
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
@Accessors(chain = true)
@Builder
public class ResponseResult<T> {
    private Integer code;
    private String msg;
    private T data;

    public static final ResponseResult<Void> SUCCESS = new ResponseResult<Void>(200, "ok", null);
    public static final ResponseResult<Void> FAIL = new ResponseResult<Void>(500, "fail", null);

    public static ResponseResult<Void> ok() {
        return new ResponseResult<Void>(200, "ok", null);
    }

    public static <T> ResponseResult<T> ok(T data) {
        return new ResponseResult<T>(200, "ok", data);
    }

    public static ResponseResult<Void> fail() {
        return ResponseResult.<Void>builder().code(500).msg("fail").build();
    }

    public static <T> ResponseResult<T> fail(T data,int code) {
        return ResponseResult.<T>builder().code(code).msg("fail").build();
    }

    public static <T> ResponseResult<T> fail(T data) {
        return ResponseResult.<T>builder().code(500).msg("fail").build();
    }
}
